package com.zoweunion.mechanic.config.wx;

import com.github.wxpay.sdk.WXPay;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 微信支付和公众号等实例配置
 */
@Configuration
public class WxConfiguration {

    /**
     * 微信支付配置
     * @param wxPay
     * @return
     */
    @Bean
    public WXPay wxPay(@Autowired WXPayConfig wxPay){
        return new WXPay(wxPay);
    }

    @Bean
    public WxMpConfigStorage wxMpConfigStorage(@Autowired WxMpConfig wxMpConfig){
        WxMpDefaultConfigImpl wxMpDefaultConfig = new WxMpDefaultConfigImpl();
        wxMpDefaultConfig.setAppId(wxMpConfig.getAppId());
        wxMpDefaultConfig.setSecret(wxMpConfig.getSecret());
        wxMpDefaultConfig.setToken(wxMpConfig.getToken());
        wxMpDefaultConfig.setAesKey(wxMpConfig.getAesKey());
        return wxMpDefaultConfig;
    }

    @Bean
    public WxMpService wxMpService(WxMpConfigStorage configStorage) {
        WxMpService wxMpService = new WxMpServiceImpl();
        wxMpService.setWxMpConfigStorage(configStorage);
        return wxMpService;
    }


}
